package com.enbatis.mybatisplugs.service.impl;

import com.enbatis.mybatisplugs.base.Account;
import com.enbatis.mybatisplugs.base.BaseServiceImpl;

import com.enbatis.mybatisplugs.commons.sql.Wrapper;
import com.enbatis.mybatisplugs.component.WebSocket;
import com.enbatis.mybatisplugs.entity.SysMsgRelUser;
import com.enbatis.mybatisplugs.entity.vo.SysMsgRelUserVO;
import com.enbatis.mybatisplugs.entity.vo.SysUserVO;
import com.enbatis.mybatisplugs.mapper.SysMsgRelUserMapper;
import com.enbatis.mybatisplugs.plugin.Pages;
import com.enbatis.mybatisplugs.service.SysMsgRelUserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* 描述：
* @author wangweidong
* @date 2019-12-17 16:23:44
*/

@Service
public class SysMsgRelUserServiceImpl extends BaseServiceImpl<SysMsgRelUserMapper,SysMsgRelUser > implements SysMsgRelUserService {

    @Autowired
    private WebSocket webSocket;

    @Override
    public int getMsgCount(Account account) {
        return selectCount(new Wrapper<>(new SysMsgRelUser()).eq("readed",0).eq("user_id",account.getId()));
    }

    @Override
    public Pages<SysMsgRelUserVO> pageVO(Page<SysMsgRelUserVO> page, SysMsgRelUserVO sysMsgRelUserVO) {
        Page returnPage= PageHelper.startPage(page.getPageNum(),page.getPageSize(),page.getOrderBy());
        baseMapper.selectVOList(sysMsgRelUserVO);
        return new Pages<>(returnPage);
    }

    @Override
    public int updateReadById(SysMsgRelUser sysMsgRelUser) {
        webSocket.sendAllMessage("");
        return updateById(sysMsgRelUser);
    }
}
